package com.lesson1.fangshua;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;


/**
 * @author liliang
 * @date 2019/5/16 15:21
 */
@Service
public class RedisServiceImpl implements RedisService {

    @Resource
    private ValueOperations<String, String> valueOperations;

    @Override
    public void put(String key, String value, long timeout) {
        valueOperations.set(key, value, timeout, TimeUnit.SECONDS);
    }


    @Override
    public Integer get(String key, Class clazz) {
        String s = valueOperations.get(key);
        if (StringUtils.isNotBlank(s)) {
            return Integer.valueOf(s);
        }
        return null;
    }

    @Override
    public void incr(String url) {
        valueOperations.increment(url, 1);
    }
}
